import reader
from reader import *
import sexprs
from sexprs import *
import tag_parser
from tag_parser import *

tagParsed, remaining = AbstractSchemeExpr.parse('4')
print(tagParsed)

tagParsed, remaining = AbstractSchemeExpr.parse('"This is String"')
print(tagParsed)
      
tagParsed, remaining = AbstractSchemeExpr.parse('yaniv a')
print(tagParsed)
      
tagParsed, remaining = AbstractSchemeExpr.parse('define')
print(tagParsed)

tagParsed, remaining = AbstractSchemeExpr.parse('(if (positive? -5) 2)')
print(tagParsed)

tagParsed, remaining = AbstractSchemeExpr.parse('(if #t 2 ,@a)')
print(tagParsed)


sexpr, remaining = AbstractSchemeExpr.parse('(cond (#t 2) (#f 3) (ELSE 4))')
print(sexpr)

sexpr, remaining = AbstractSchemeExpr.parse('(cond (ELSE 4))')
print(sexpr)

#sexpr, remaining = sexprs.AbstractSexpr.readFromString('(cond (#t 2) (ELSE 3))')
#print(IfThenElse.isCond(sexpr))

sexpr,asd = sexprs.AbstractSexpr.readFromString('(a as 3 4 4 . d)')
print(sexpr)
#sexpr = LambdaSimple.isLambdaSimpleParameter(sexpr)
#rint(sexpr)

print(AbstractSchemeExpr.getTagParsedList(sexpr))

sexpr, remaining = AbstractSchemeExpr.parse('(lambda (xa as ASA323 d s) (if (positive? -5) 2))')
print(sexpr)

sexpr, remaining = AbstractSchemeExpr.parse('(lambda s (apply x s))')
print(sexpr)

sexpr, remaining = AbstractSchemeExpr.parse('(lambda (xa as ASA323 d . s) (if (lambda s s) 2))')
print(sexpr)

sexpr,asd = sexprs.AbstractSexpr.readFromString('(a as sl sl sl . dl)')

sexpr = LambdaVar.isLambdaVarParameter(sexpr)
print(sexpr)


sexpr, remaining = AbstractSchemeExpr.parse('(lambda (xa as ASA323 d s) (if (positive? -5) 2))')
print(sexpr)


sexpr, remaining = AbstractSchemeExpr.parse('(or (positive? -5) 1)')
print(sexpr)



sexpr, remaining = AbstractSchemeExpr.parse('(and #f (error "doesn\'t get here"))')
print(sexpr)

sexpr, remaining = AbstractSchemeExpr.parse('(and #t 5)')
print(sexpr)



sexpr,asd = sexprs.AbstractSexpr.readFromString('(define x 3)')

sexpr = Def.isSimpleDef(sexpr)
print(sexpr)


sexpr,asd = sexprs.AbstractSexpr.readFromString('(define(s . b) c)')

sexpr = Def.isMITDef(sexpr)
print(sexpr)



sexpr, remaining = AbstractSchemeExpr.parse('(define x asdasd)')
print(sexpr)


sexpr, remaining = AbstractSchemeExpr.parse('(define(s . (asd a a .s )) c)')
print(sexpr)


sexpr,asd = sexprs.AbstractSexpr.readFromString('(let ((a 8) (b 8)) c)')
print(Applic.getApplicFromLet(sexpr))
print(Applic.isLet(sexpr))


sexpr, remaining = AbstractSchemeExpr.parse('(let ((a (lambda (x) x)) (b 8)) (a b))')
print(sexpr)


testStr = '''(let* ((x 1)
         (y (+ x 1)))
    (list y x))'''
sexpr,asd = sexprs.AbstractSexpr.readFromString(testStr)
print(Applic.getLetFromLetStar(sexpr))
print(Applic.isLetStar(sexpr))

sexpr, remaining = AbstractSchemeExpr.parse(testStr)
print(sexpr)


testStr = '''(let ((x 4)) (let* ((x 6) (y (+ x 2))) (* x y)))'''
sexpr,asd = sexprs.AbstractSexpr.readFromString(testStr)
sexpr, remaining = AbstractSchemeExpr.parse(testStr)
print(sexpr)


testStr = '''(let () 3)'''
sexpr,asd = sexprs.AbstractSexpr.readFromString(testStr)
sexpr, remaining = AbstractSchemeExpr.parse(testStr)
print(sexpr)


testStr = '''(letrec ((g1 <LE1>)
	 (g2 <LE2>)
	 (g3 <LE3>))
  <expr>)'''
sexpr,asd = sexprs.AbstractSexpr.readFromString(testStr)
print(Applic.getYagFromLetrec(sexpr))

sexpr, remaining = AbstractSchemeExpr.parse(testStr)
print(sexpr)

testStr = '''(lambda (x) (+ x 1))'''
sexpr, remaining = AbstractSchemeExpr.parse(testStr)
print(sexpr)



testStr ="'12345"
sexpr, remaining = AbstractSchemeExpr.parse(testStr)
print(sexpr)



print('')
print('')
print('')
print('')


testStr ="`(1 2 ,@(lambda (x) (+ 1 x)))"
sexpr, remaining = sexprs.AbstractSexpr.readFromString(testStr)
print(sexpr)
after = QQuote.qqexpander(sexpr.cdr().car())
print(after)
sexpr = AbstractSchemeExpr.TagParse(after)
print(sexpr)


testStr ="`(1 ,@#(2 3) 4)"
sexpr, remaining = sexprs.AbstractSexpr.readFromString(testStr)
print(sexpr)
after = QQuote.qqexpander(sexpr.cdr().car())
print(after)
sexpr = AbstractSchemeExpr.TagParse(after)
print(sexpr)
